from __future__ import annotations

from dataclasses import dataclass


@dataclass
class ReevingResult:
    parts_of_line: int
    efficiency: float
    running_rope_tension_kN: float
    dead_end_tension_kN: float
    hook_load_kN: float
    note: str


def reeving_analysis(hook_load_kN: float, parts_of_line: int, sheave_loss_per_pass: float = 0.02, bearing_loss_per_pass: float = 0.01, dead_end_eff_factor: float = 0.98) -> ReevingResult:
    """滑车组详细效率与跑绳/出端头拉力。

    - 每过一只滑轮，效率乘以 (1 - ϕ)，ϕ = sheave_loss + bearing_loss
    - 整体效率 η_total = Π(1-ϕ)^{passes}
    - 跑绳张力 ≈ Hook / (η_total · n)
    - 出端头（死端）张力 ≈ 跑绳张力 × dead_end_eff_factor
    """

    passes = max(0, parts_of_line)
    phi = max(0.0, sheave_loss_per_pass + bearing_loss_per_pass)
    eta = (1.0 - phi) ** passes
    running = hook_load_kN / max(1e-6, eta * max(1, parts_of_line))
    dead_end = running * dead_end_eff_factor
    return ReevingResult(parts_of_line=parts_of_line, efficiency=eta, running_rope_tension_kN=running, dead_end_tension_kN=dead_end, hook_load_kN=hook_load_kN, note="经验效率，建议现场校核")


